﻿using EContractServer.SecurityLibrary;
using System.Security.Cryptography;
using System.Text;
using System.IO;

namespace TestMain
{
    class Program
    {
        static void Main( string[] args )
        {
            RSACrytography crytography = new RSACrytography();
            string l_sKeyFile = @"D:\test\Crytography\key.xml";
            string l_sPulbicKeyFile = @"D:\test\Crytography\publickey.xml";
            string l_sOrigin = string.Empty;
            string l_sOriginFile = @"D:\test\Crytography\abc.txt";
            string l_sCypher = string.Empty;
            string l_sCypherFile = @"D:\test\Crytography\xyz.txt";
            string l_sDecryptString = string.Empty;
            string l_sDecryptStringFile = @"D:\test\Crytography\def.txt";
            int l_iBitStrength = 1024;

            Stream a;
            a.Seek( 0, SeekOrigin.Begin );
            // Generate key
            crytography.GenerateKey( l_iBitStrength, true, true );

            //
            // Using AES for 

            //// Write Original string
            //l_sOrigin = Utility.ReadFile( l_sOriginFile );
            //if ( l_sOrigin.Length <= 128 )
            //{
            //    System.Console.WriteLine( l_sOriginFile );

            //    // Encrypt
            //    l_sCypher = crytography.EncryptString( Utility.ReadKeyFile( l_sPulbicKeyFile, out l_iBitStrength ), Utility.ReadFile( l_sOriginFile ) );
            //    Utility.WriteFile( l_sCypherFile, l_sCypher );
            //    //System.Console.WriteLine( l_sCypher );

            //    //Decrypt
            //    l_sDecryptString = crytography.DecryptString( Utility.ReadKeyFile( l_sKeyFile, out l_iBitStrength ), l_sCypher );
            //    Utility.WriteFile( l_sDecryptStringFile, l_sDecryptString );
            //    //System.Console.WriteLine( l_sDecryptString );
            //}
            //else
            //{
            //    // Using MD5 hash
            //    byte[]abc =  MD5.Create().ComputeHash(Encoding.UTF8.GetBytes( l_sOrigin ));
            //    System.Console.WriteLine( abc.GetLength( 0));
            //    foreach ( int item in abc )
            //    {
            //        System.Console.Write( item );
            //    }
            //    System.Console.ReadLine();

            //    // Encrypte
            //    l_sCypher = crytography.EncryptByteNumber( Utility.ReadKeyFile( l_sPulbicKeyFile, out l_iBitStrength ), abc );
            //    System.Console.WriteLine( l_sCypher );

            //    //Decrypt
            //    l_sDecryptString = crytography.DecryptString( Utility.ReadKeyFile( l_sKeyFile, out l_iBitStrength ), l_sCypher );
            //    Utility.WriteFile( l_sDecryptStringFile, l_sDecryptString );
            //}

            System.Console.ReadLine();
        }
    }
}
